﻿Imports SdlDotNet.Graphics
Imports SdlDotNet.Graphics.Sprites
Imports SdlDotNet.Input
Imports SdlDotNet.Audio
Imports System.Drawing

Public Class MainMenu
    Implements IScreen

    Private Background As Sprite
    Private NewGameButton As AnimatedSprite
    Private QuitGameButton As AnimatedSprite

    Public Event RequestedNewGame()
    Public Event RequestedQuit()

    Public Sub New()
        InitializeSprites()
    End Sub

    Public Sub Draw(ByRef display As Surface) Implements IScreen.Draw
        display.Blit(Background)
        display.Blit(NewGameButton)
        display.Blit(QuitGameButton)
    End Sub

    Private Sub InitializeSprites()
        Background = New Sprite(New Surface("Resources/images/menu/menubackground.jpg"), New Point(0, 0))

        Dim newGameButtonSurfaces As New SurfaceCollection()
        newGameButtonSurfaces.Add(New Surface("Resources/images/menu/newgame.png"))
        newGameButtonSurfaces.Add(New Surface("Resources/images/menu/newgame2.png"))
        NewGameButton = New AnimatedSprite(newGameButtonSurfaces, New Point(580, 485))
        NewGameButton.Animate = False

        Dim quitGameButtonSurfaces As New SurfaceCollection()
        quitGameButtonSurfaces.Add(New Surface("Resources/images/menu/quitgame.png"))
        quitGameButtonSurfaces.Add(New Surface("Resources/images/menu/quitgame2.png"))
        QuitGameButton = New Sprites.AnimatedSprite(quitGameButtonSurfaces, New Point(580, 530))
        QuitGameButton.Animate = False
    End Sub

    Public Sub Dispose() Implements IScreen.Dispose
        Background.Dispose()
        NewGameButton.Dispose()
        QuitGameButton.Dispose()
    End Sub

    Public Sub HandleKeyboardUp(ByVal sender As Object, ByVal e As KeyboardEventArgs) Implements IScreen.HandleKeyboardUp
        If (e.Key = Key.Escape) Then
            RaiseEvent RequestedQuit()
        End If
    End Sub

    Public Sub HandleMouseButtonUp(ByVal sender As Object, ByVal e As MouseButtonEventArgs) Implements IScreen.HandleMouseButtonUp
        If (NewGameButton.IntersectsWith(e.Position)) Then
            CommonSounds.Click.Play()
            RaiseEvent RequestedNewGame()
        ElseIf (QuitGameButton.IntersectsWith(e.Position)) Then
            CommonSounds.Click.Play()
            RaiseEvent RequestedQuit()
        End If
    End Sub

    Public Sub HandleMouseMotion(ByVal sender As Object, ByVal e As MouseMotionEventArgs) Implements IScreen.HandleMouseMotion
        NewGameButton.Frame = 0
        QuitGameButton.Frame = 0

        If (NewGameButton.IntersectsWith(e.Position)) Then
            NewGameButton.Frame = 1
        ElseIf (QuitGameButton.IntersectsWith(e.Position)) Then
            QuitGameButton.Frame = 1
        End If
    End Sub

End Class
